package com.renwei.sample.controller;

import com.renwei.db.DynamicDataSourceHolder;
import com.renwei.sample.domain.User;
import com.renwei.sample.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class SampleController {

	@Autowired
	private UserService userService;

	private static Logger log = Logger.getLogger(SampleController.class);

	@RequestMapping("sample")
	public String sample(@RequestParam(value="name",required=false,defaultValue="renwei") String name, Model model){
		DynamicDataSourceHolder.setDataSource("dataSource2");
		List<User> userList = userService.loadUsers(2,1);
		model.addAttribute("name", userList.get(0).getName());

		return "sample/sample";
	}
}
